/**
 * SearchResultTableModel.java
 * @author Daniel Liu
 * Create: 2007-1-3 ����06:53:30
 */
package org.lex.ftp.ui.find.old.speed;

import java.util.Iterator;
import java.util.Vector;

import javax.swing.table.AbstractTableModel;

import org.lex.net.ftp.FTPFile;
import org.lex.net.ftp.FTPURL;


public class SearchResultTableModel extends AbstractTableModel {
	private static final String[] columnNames = { "Name", "Server", "Path", "Size", "Modified", "Attribute" };
	private Vector<Entry> data = null;

	public SearchResultTableModel() {
		super();
		this.data = new Vector<Entry>();
	}

	public void addSearchResult(SearchResult result) {
		Iterator<FTPFile> itor = result.fileEntryList.iterator();
		while (itor.hasNext()) {
			Entry entry = new Entry();
			entry.file = itor.next();
			entry.url = result.url;
			this.data.add(entry);
		}
		this.fireTableDataChanged();
	}

	public void clear() {
		this.data.clear();
		this.fireTableDataChanged();
	}

	public String getColumnName(int column) {
		return columnNames[column];
	}

	public int getColumnCount() {
		return columnNames.length;
	}

	public int getRowCount() {
		return data.size();
	}

	public Object getValueAt(int row, int column) {
		/*
		 * Name, Server, Path, Size, Modified, Attribute
		 */
		Entry entry = this.data.get(row);
		switch (column) {
		case 0:
			return entry.file;
		case 1:
			return entry.url.getHost();
		case 2:
			return entry.url.getPath();
		case 3:
			return entry.file.getSize();
		case 4:
			return entry.file.getDate();
		case 5:
			return entry.file.getAttribute();
		}
		return "";
	}
}

class Entry {
	public FTPURL url = FTPURL.FAKE_URL;
	public FTPFile file = FTPFile.FAKE_ROOT;
}
